﻿using System.Data;

// ReSharper disable once CheckNamespace
namespace com.kmer.Module
{
    /// <summary>
    /// 用户类
    /// </summary>
    public class kmerUser {
		/// <summary>
		/// 用户登录系统之后需要做的事情统一在这里做完
		/// 调用此方法前请保证输入的数据有效（用户是合法登录的）这个方法不是做登录验证的
		/// 为了兼容现在的代码所以使用现在的数据
		/// </summary>
		/// <param name="dv"></param>
		/// <param name="pOpenID"></param>
		public static void DoLogin(DataView dv, string pOpenID = "") {
			DoLogin(dv.Table, pOpenID);
		}
		/// <summary>
		/// 用户登录系统之后需要做的事情统一在这里做完
		/// 调用此方法前请保证输入的数据有效（用户是合法登录的）这个方法不是做登录验证的
		/// 为了兼容现在的代码所以使用现在的数据
		/// </summary>
		/// <param name="table"></param>
		/// <param name="pOpenID"></param>
		public static void DoLogin(DataTable table, string pOpenID = "") {
			var line = 0;
			//try {
				//UserInfo.CusNo = table.Get<string>(0, "LoginID");
				//line = 1;
				//UserInfo.CusIDInt = table.Get<int>("CusID");
				//UserInfo.CusID = table.Get<int>("CusID").ToString();
				//UserInfo.CusImg = table.Get<string>("PhotoPath");
				//UserInfo.CusType = table.Get<string>("CusType");

				//UserInfo.RankTitle = table.Get<string>("RankTitle");

				//UserInfo.OpenID = pOpenID;
				//UserInfo.OpenID = table.Get<string>("OauthCusNo");
				//HttpContext.Current.SetCookie("OpenID", UserInfo.OpenID);
				//UserInfo.CusName = string.IsNullOrWhiteSpace(table.Get<string>("CusName"))
				//	? UserInfo.CusNo
				//	: table.Get<string>("CusName");
				//line = 100;
				//UserInfo.IsTestUser = table.Get<bool>("IsTestUser");
				//line = 101;
				//UserInfo.IsActivate = table.Get<bool>("IsActivate");
				//line = 102;
				//UserInfo.RankID = table.Get<int>("RankID");
				//line = 103;
				//UserInfo.ExpiredTime = table.Get<DateTime>("ExpiredTime");

				//登陆重构购物车 
				//CartEvent.get_cart_Login();
				/*
				using (ShoppingCart Cart = new ShoppingCart()){
					bool b = Cart.ReCart();
				} 
				//*/

				//更新个人信息(登陆次数，上次登陆时间，最后登陆时间)
			//	var lastLoginDate = table.Get<DateTime>("LastLoginDate");
			//	var loginCount = table.Get<int>("LoginCount");
			//	HookService.Instance.Invoke((int)HookTypes.AFTER_USER_LOGIN, UserInfo.CusID, loginCount, lastLoginDate);
			//} catch (InvalidCastException) {
			//	Log.WriteLog(line.ToString());
			//} catch (Exception ex) {
			//	Log.Error(ex);
			//}

			/*
			string strLastLoginDate = table.Get<DateTime>("LastLoginDate").ToString();
			string strLoginCount = table.Get<int>("LoginCount").ToString();
			string strCusID = UserInfo.CusID;
			var web = new WebControler();
			web.wahRegCusUpdateGet(strCusID, strLoginCount, strLastLoginDate);

			//更新积分
			var m_Flow = new Flow();
			m_Flow.FlwCusScoreFlow("6", UserInfo.CusID, "特点日期登录", "");
			//*/
			//OnlineUsers.AddAndRefresh();
		}
	
		

		/// <summary>
		/// 退出系统
		/// </summary>
		public static void DoLogout() {
			OnlineUsers.RemoveUser();
			//HookService.Instance.Invoke((int)HookTypes.AFTER_USER_LOGOUT);
			
		}
	}
}
